//
//  QK.h
//  Chart
//
//  Created by CaoJun on 15/3/30.
//
//

#ifndef __Chart__QK__
#define __Chart__QK__

#include "KLineData.h"
#include "IndexData.h"

#include <string>
#include <vector>

namespace ytx
{
    
    namespace QKType {
        enum QKType {
            Short = -1,
            Flat = 0,
            Long = 1
        };
    }
    
    struct QKItem
    {
        YTXTime tradedatepre;
        QKType::QKType type;
        YTXTime tradedatenext;
    };
    
    class QK : public IndexData
    {
    public:
        QK(IndexConfig indexConfig);
        
        virtual void calculate(Quotation * data);
        
        virtual void updateLastest(Quotation * data);
        
        virtual void callback(std::string tag, std::string data);
        
        virtual void onFail(std::string tag);
        
        virtual void clearIfParentDataChanged(const Quotation * data);
        
        virtual void cleanData();
    private:
        bool requesLock;
        
    protected:
        KLineData * kLineData;
        std::vector<QKItem> QKData;
        virtual std::vector<QKItem> getQKDataFromDB();
        virtual bool updateQKData(QKItem);
        virtual void getQKData();
        virtual void requestQKData(std::string date);
        virtual void responseQKData(YTXJson::Value data, YTXJson::Value info);
        virtual bool QKDataIsEnough();
        virtual bool saveQKDataToDB(std::vector<QKItem>);
        virtual bool hasQKData();
        virtual void setQKData(QKItem qk);
        
        virtual void realCalculate(KLineData * data);
    };
}

#endif /* defined(__Chart__QK__) */
